package com.kupurui.asteacher.ui.mine.message;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.frame.util.AppJsonUtil;
import com.kupurui.asteacher.R;
import com.kupurui.asteacher.bean.MessageInfo;
import com.kupurui.asteacher.http.MessageReq;
import com.kupurui.asteacher.ui.BaseAty;
import com.kupurui.asteacher.ui.index.BindingAuditAty;
import com.kupurui.asteacher.utils.UserManger;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 消息
 * Created by Administrator on 2017/7/17.
 */

public class MessageAty extends BaseAty {


    @Bind(R.id.tv_bar_title)
    TextView tvBarTitle;
    @Bind(R.id.m_toolbar)
    Toolbar mToolbar;
    @Bind(R.id.tv_time)
    TextView tvTime;
    @Bind(R.id.tv_time1)
    TextView tvTime1;
    @Bind(R.id.tv_work_num)
    TextView tvWorkNum;
    @Bind(R.id.ll_work_message)
    LinearLayout llWorkMessage;
    @Bind(R.id.tv_notice_num)
    TextView tvNoticeNum;
    @Bind(R.id.ll_notice_message)
    LinearLayout llNoticeMessage;
    @Bind(R.id.tv_work_content)
    TextView tvWorkContent;
    @Bind(R.id.tv_notice_message)
    TextView tvNoticeMessage;

    MessageInfo messageInfo;

    @Override
    public int getLayoutId() {
        return R.layout.message_aty;
    }

    @Override
    public void initData() {
        initToolbar(mToolbar, "消息");
    }

    @Override
    public void requestData() {
        showLoadingContent();
        new MessageReq().message(UserManger.getId(), this, 0);
    }

    @OnClick({R.id.ll_notice_message, R.id.ll_work_message})
    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.ll_notice_message://通知消息
                startActivity(NoticeMessageAty.class, null);
                break;
            case R.id.ll_work_message:
                startActivity(BindingAuditAty.class, null);
                break;
        }
    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        switch (what) {
            case 0:
                messageInfo = AppJsonUtil.getObject(result,MessageInfo.class);
                if (messageInfo.getWork().equals("0")){
                    tvWorkNum.setVisibility(View.GONE);
                    tvWorkContent.setText("暂无审核消息");
                }else{
                    tvWorkNum.setVisibility(View.VISIBLE);
                    tvWorkNum.setText(messageInfo.getWork());
                }

                if (messageInfo.getInform().equals("0")){
                    tvNoticeMessage.setText("暂无通知消息");
                    tvNoticeNum.setVisibility(View.GONE);
                }else {
                    tvNoticeNum.setVisibility(View.VISIBLE);
                    tvNoticeNum.setText(messageInfo.getInform());
                }
                break;
        }
        super.onSuccess(result, call, response, what);
    }

}
